﻿using Abp.Domain.Entities;
using Batman.Jianbei.Forum.Core.Domains.Dicts;
using System;
using System.ComponentModel.DataAnnotations;

namespace Batman.Jianbei.Forum.Core.Domains.Pumps
{
    /// <summary>
    /// 胰岛素泵销售信息（胰岛素泵资料卡）
    /// </summary>
    public class PumpSaleInfo : Entity<string>
    {
        /// <summary>
        /// 客户姓名
        /// </summary>
        public string CustomerName { get; set; }

        /// <summary>
        /// 胰岛素泵号
        /// </summary>
        [Display(Name = "胰岛素泵号")]
        [MaxLength(35)]
        [Required]
        public string PumpNo { get; set; }

        /// <summary>
        /// 客户电话号码
        /// </summary>
        [Display(Name = "客户电话号码")]
        [MaxLength(20)]
        [Required]
        public string Phone { get; set; }

        /// <summary>
        /// 胰岛素泵型号
        /// </summary>
        [Display(Name = "胰岛素泵型号")]
        [MaxLength(36)]
        [Required]
        public string PumpModelId { get; set; }

        /// <summary>
        /// 胰岛素泵型号
        /// </summary>
        public PumpModel PumpModel { get; set; }

        /// <summary>
        /// 购买时间
        /// </summary>
        [Display(Name = "购买时间")]
        [Required]
        public DateTime PurchaseAt { get; set; }

        /// <summary>
        /// 保修时开始时间
        /// </summary>
        [Display(Name = "保修时开始时间")]
        [Required]
        public DateTime WarrantyStart { get; set; }

        /// <summary>
        /// 保修时结束时间
        /// </summary>
        [Display(Name = "保修时结束时间")]
        [Required]
        public DateTime WarrantyEnd { get; set; }

        [Required]
        [MaxLength(36)]
        public string CreateBy { get; set; }

        [Required]
        public DateTime CreateAt { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 计算有效期 如果传入的数据有值 则传入的时间设为结束时间 否则4年后是结束时间
        /// </summary>
        public void CalWarranty(DateTime? warrantyEnd = null)
        {
            if (warrantyEnd.HasValue)
            {
                this.WarrantyEnd = warrantyEnd.Value;
                return;
            }

            this.WarrantyStart = this.PurchaseAt;
            this.WarrantyEnd = this.PurchaseAt.AddYears(4); // 默认保修时长4年
        }
    }
}
